import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
import { System } from "./System";

export function get_string_from_oss(
  system: System,
  path: string
): Promise<string> {
  const s3: S3Client = system.s3Client;
  const command2 = new GetObjectCommand({
    Bucket: system.bucket,
    Key: path,
  });
  return s3
    .send(command2)
    .then((res: any) => {
      return res.Body?.transformToString();
    })
    .then((str: string) => {
      if (str) {
        return Promise.resolve(str);
      } else {
        return Promise.reject(false);
      }
    });
}
